﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Pyramid.Hardware;
using Pyramid.Hardware.Operations;
using Pyramid.Hardware.Interop;

namespace Pyramid.Tests
{
    [TestClass]
    public class HalfAdderFixture
    {
        [TestMethod]
        public void ShouldPerformAllHalfAdds()
        {
            int[][] testData = new int[][]
            {
                new int[]{1, 1, -1, 1},
                new int[]{1, 0, 1, 0},
                new int[]{1, -1, 0, 0},
                new int[]{0, 1, 1, 0},
                new int[]{0, 0, 0, 0},
                new int[]{0, -1, -1, 0},
                new int[]{-1, 1, 0, 0},
                new int[]{-1, 0, -1, 0},
                new int[]{-1, -1, 1, -1}
            };

            foreach (var row in testData)
            {
                ShouldPerformHalfAdd(row[0], row[1], row[2], row[3]);
            }
        }

        public void ShouldPerformHalfAdd(int A, int B, int ExpectedSum, int ExpectedCarry)
        {
            HalfAdder halfAdder = new HalfAdder(new VariableInputLine(A), new VariableInputLine(B));
            Assert.AreEqual((Trivalent)ExpectedSum, halfAdder.Sum.Signal);
            Assert.AreEqual((Trivalent)ExpectedCarry, halfAdder.Carry.Signal);
        }
    }
}
